package com.example.mall.web.controller;

import com.example.mall.domain.LogisticsFeeRules;
import com.example.mall.dto.LogisticsFeeRulesDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.LogisticsFeeRulesQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ILogisticsFeeRulesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logisticsFeeRules")
public class LogisticsFeeRulesController {

    @Autowired
    public ILogisticsFeeRulesService logisticsFeeRulesService;

    /**
     * 分页查询物流费用规则表信息
     * @param logisticsFeeRulesQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询物流费用规则表信息",notes = "分页查询物流费用规则表信息",httpMethod = "GET")
    public JSONResult queryPage(LogisticsFeeRulesQuery logisticsFeeRulesQuery){
        PageDTO<LogisticsFeeRulesDto> logisticsFeeRulesDtoPageDTO = logisticsFeeRulesService.queryPage(logisticsFeeRulesQuery);
        return JSONResult.success("查询成功",logisticsFeeRulesDtoPageDTO);
    }

    /**
     * 根据id查询物流费用规则表信息
     * @param ruleId
     * @return
     */
    @GetMapping("query/{ruleId}")
    @ApiOperation(value = "根据id查询物流费用规则表信息",notes = "根据id查询物流费用规则表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("ruleId")Long ruleId){
        //1.根据id查询用户信息
        if (ruleId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOGISTICSFEERULESID_NOT_ID);
        }
        LogisticsFeeRules logisticsFeeRules = logisticsFeeRulesService.getById(ruleId);
        return JSONResult.success("查询成功",logisticsFeeRules);
    }

    /**
     * 根据id查询物流费用规则表信息
     * @param ruleId
     * @return
     */
    @GetMapping("queryLogisticsFeeRulesById/{ruleId}")
    @ApiOperation(value = "根据id查询物流费用规则表信息",notes = "根据id查询物流费用规则表信息",httpMethod = "GET")
    public JSONResult queryLogisticsFeeRulesById(@PathVariable("ruleId")Long ruleId){
        //1.根据id查询用户信息
        if (ruleId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOGISTICSFEERULESID_NOT_ID);
        }
        LogisticsFeeRules logisticsFeeRules = logisticsFeeRulesService.queryLogisticsFeeRulesById(ruleId);
        return JSONResult.success("查询成功",logisticsFeeRules);
    }

    /**
     * 查询全部物流费用规则表信息
     * @param
     * @return
     */
    @GetMapping("queryLogisticsFeeRulesList")
    @ApiOperation(value = "查询全部物流费用规则表信息",notes = "查询全部物流费用规则表信息",httpMethod = "GET")
    public JSONResult queryLogisticsFeeRulesList(){
        List<LogisticsFeeRules> logisticsFeeRules = logisticsFeeRulesService.queryLogisticsFeeRulesList();
        return JSONResult.success("查询成功",logisticsFeeRules);
    }

    /**
     * 新增物流费用规则表
     * @param logisticsFeeRulesDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增物流费用规则表",notes = "新增物流费用规则表",httpMethod = "POST")
    public JSONResult insert(@RequestBody LogisticsFeeRulesDto logisticsFeeRulesDto){
        logisticsFeeRulesService.insert(logisticsFeeRulesDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改物流费用规则表信息
     * @param logisticsFeeRulesDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改物流费用规则表信息",notes = "修改物流费用规则表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody LogisticsFeeRulesDto logisticsFeeRulesDto){
        logisticsFeeRulesService.update(logisticsFeeRulesDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除物流费用规则表信息
     * @param ruleId
     * @return
     */
    @PostMapping("delete/{ruleId}")
    @ApiOperation(value = "删除物流费用规则表信息",notes = "删除物流费用规则表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("ruleId") Long ruleId) {
        logisticsFeeRulesService.delete(ruleId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除物流费用规则表信息
     * @param ruleIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除物流费用规则表信息",notes = "批量删除物流费用规则表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ruleIds) {
        logisticsFeeRulesService.deleteBatch(ruleIds);
        return JSONResult.success("批量删除成功");
    }
}
